{% for vhost in nginx_vhosts %}
server {
    listen {{ vhost.listen | default('80') }};
{% if vhost.server_name is defined %}
    server_name {{ vhost.server_name }};
{% endif %}
{% if vhost.ssl_certificate is defined %}
    ssl_certificate {{ vhost.ssl_certificate }};
{% endif %}
{% if vhost.ssl_certificate_key is defined %}
    ssl_certificate_key {{ vhost.ssl_certificate_key }};
{% endif %}
{% if vhost.root is defined %}
    root {{ vhost.root }};
{% endif %}
{% if vhost.index is defined%}
    index {{ vhost.index | default('index.html index.htm') }};
{% endif %}
	
{% if vhost.error_page is defined %}
    error_page {{ vhost.error_page }};
{% endif %}
{% if vhost.access_log is defined %}
    access_log {{ vhost.access_log }};
{% endif %}
{% if vhost.error_log is defined %}
    error_log {{ vhost.error_log }};
{% endif %}
{% if vhost.rewrite is defined %}
    rewrite {{ vhost.rewrite }};
{% endif %}

{% if vhost.nginx_use_proxy %}
{% for proxy in vhost.nginx_proxies %} 
    location {{ proxy.location }} { 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-Proto http; 
        proxy_set_header X-Url-Scheme $scheme; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $http_host; 
        proxy_set_header X-NginX-Proxy true; 
        proxy_redirect off; 
        proxy_pass http://{{ proxy.name }}; 
        break;
    }
{% endfor %}
{% endif %}
	
{% if vhost.nginx_server_static %} 
    location / { 
        try_files $uri $uri/ = 404; 
    } 
{% endif %}
}
{% endfor %}
